package strategy_pattern.context;

import strategy_pattern.strategy.PriceStrategy;
import strategy_pattern.strategy.UserType;
import strategy_pattern.strategy.impl.DiscountStrategy;
import strategy_pattern.strategy.impl.FullReductionStrategy;
import strategy_pattern.strategy.impl.NoDiscountStrategy;

import java.util.HashMap;
import java.util.Map;

public class PriceContext {
    private static final Map<UserType, PriceStrategy> PRICE_STRATEGY_MAP = new HashMap<>();

    static {
        PRICE_STRATEGY_MAP.put(UserType.NORMAL, new NoDiscountStrategy());
        PRICE_STRATEGY_MAP.put(UserType.VIP, new DiscountStrategy());
        PRICE_STRATEGY_MAP.put(UserType.SUPER_VIP, new FullReductionStrategy());
    }

    private final PriceStrategy priceStrategy;

    public PriceContext(UserType userType) {
        this.priceStrategy = PRICE_STRATEGY_MAP.get(userType);
    }

    public double calculate(double price) {
        return priceStrategy.calculate(price);
    }


}
